
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class SoltUI : MonoBehaviour,IPointerClickHandler
{
    public int index;
    private SoltData data;
    public Image Icon;
    public TextMeshProUGUI countText;
    public void SetData(SoltData data)
    {
        this.data = data;
        data.AddListener(OnDataChange);
        UpdateUI();
    }
    public SoltData GetData()
    {
        return data;
    }
    private void OnDataChange()
    {
        UpdateUI(); 
    }
    public void UpdateUI()
    {
        if (this.data.item == null)
        {
            Icon.enabled = false;
            countText.enabled = false;
        }
        else
        {
            Icon.enabled = true;
            countText.enabled = true;
            Icon.sprite = data.item.sprite;
            countText.text = data.count.ToString();
        }
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        ItemMoveHider.Instance.OnClickSolt(this);
    }
}
